<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="姓名" prop="realName">
            <el-input v-model="form.realName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="性别" prop="sex">
            <el-select v-model="form.sex" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.sex_status"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="出生日期" prop="birthData">
            <el-date-picker v-model="form.birthData" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="身份证号" prop="idCard">
            <el-input v-model="form.idCard" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="学校" prop="school">
            <el-input v-model="form.school" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="班级" prop="classes">
            <el-input v-model="form.classes" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="专业" prop="major">
            <el-input v-model="form.major" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="学号" prop="stuNo">
            <el-input v-model="form.stuNo" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="解答科目" prop="answerSubject">
            <el-input v-model="form.answerSubject" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="认证状态">
            <el-select v-model="form.status" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.auth_status"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column v-if="columns.visible('realName')" prop="realName" label="姓名" />
        <el-table-column v-if="columns.visible('sex')" prop="sex" label="性别">
          <template slot-scope="scope">
            {{ dict.label.sex_status[scope.row.sex] }}
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('birthData')" prop="birthData" label="出生日期">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.birthData) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('idCard')" prop="idCard" label="身份证号" />
        <el-table-column v-if="columns.visible('school')" prop="school" label="学校" />
        <el-table-column v-if="columns.visible('classes')" prop="classes" label="班级" />
        <el-table-column v-if="columns.visible('major')" prop="major" label="专业" />
        <el-table-column v-if="columns.visible('stuNo')" prop="stuNo" label="学号" />
        <el-table-column v-if="columns.visible('answerSubject')" prop="answerSubject" label="解答科目" />
        <el-table-column v-if="columns.visible('status')" prop="status" label="认证状态">
          <template slot-scope="scope">
            {{ dict.label.auth_status[scope.row.status] }}
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('createTime')" prop="createTime" label="创建时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('updateTime')" prop="updateTime" label="更新时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.updateTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-permission="['admin','authData:edit','authData:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudAuthData from '@/api/authData'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

// crud交由presenter持有
const defaultCrud = CRUD({ title: 'auth_data', url: 'api/authData', sort: 'id,desc', crudMethod: { ...crudAuthData }})
const defaultForm = { id: null, realName: null, sex: null, birthData: null, idCard: null, school: null, classes: null, major: null, stuNo: null, answerSubject: null, status: null, createTime: null, updateTime: null }
export default {
  name: 'AuthData',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  dicts: ['sex_status', 'auth_status'],
  data() {
    return {
      permission: {
        add: ['admin', 'authData:add'],
        edit: ['admin', 'authData:edit'],
        del: ['admin', 'authData:del']
      },
      rules: {
        realName: [
          { required: true, message: '姓名不能为空', trigger: 'blur' }
        ],
        sex: [
          { required: true, message: '性别不能为空', trigger: 'blur' }
        ],
        birthData: [
          { required: true, message: '出生日期不能为空', trigger: 'blur' }
        ],
        idCard: [
          { required: true, message: '身份证号不能为空', trigger: 'blur' }
        ],
        school: [
          { required: true, message: '学校不能为空', trigger: 'blur' }
        ],
        classes: [
          { required: true, message: '班级不能为空', trigger: 'blur' }
        ],
        major: [
          { required: true, message: '专业不能为空', trigger: 'blur' }
        ],
        stuNo: [
          { required: true, message: '学号不能为空', trigger: 'blur' }
        ],
        answerSubject: [
          { required: true, message: '解答科目不能为空', trigger: 'blur' }
        ]
      }}
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
